{% extends "h:templates/layouts/admin.html.jinja2" %}

{% set page_id = 'search' %}
{% set page_title = 'Search index' %}

{% macro reindex_form(heading, action) %}
  <div class="panel panel-default">
    <div class="panel-heading">
      <h3 class="panel-title">{{ heading }}</h3>
    </div>

    <div class="panel-body">
      <form method="POST">
        <input type="hidden" name="csrf_token" value="{{ get_csrf_token() }}">
        {{ caller() }}
        <div class="form-group">
          <input type="submit" class="btn btn-default" name="{{ action }}" value="Reindex">
        </div>
      </form>
    </div>
  </div>
{% endmacro %}

{% macro force_checkbox(name) %}
  <div class="form-group form-check">
    <input class="form-check-input" type="checkbox" checked id="{{ name }}" name="{{ name }}">
    <label class="form-check-label" for="{{ name }}">Force <small class="text-muted">(Reindex all matching annotations even if they're already up to date in Elasticsearch.)</small></label>
  </div>
{% endmacro %}

{% block content %}
  <p>This is the search index admin page.</p>

  {% call reindex_form(heading="Reindex all annotations between two dates", action="reindex_date") %}
    <div class="form-group">
      <label for="start">Start date</label>
      <input required type="datetime-local" class="form-control" name="start" id="start">
    </div>

    <div class="form-group">
      <label for="end">End date</label>
      <input required type="datetime-local" class="form-control" name="end" id="end">
    </div>
  {% endcall %}

  {% call reindex_form(heading="Reindex all annotations by a user", action="reindex_user") %}
    <div class="form-group">
      <label for="username">Username</label>
      <input required class="form-control" name="username" id="username">
    </div>

    {{ force_checkbox("reindex_user_force") }}
  {% endcall %}

  {% call reindex_form(heading="Reindex all annotations in a group", action="reindex_group") %}
    <div class="form-group">
      <label for="groupid">Group ID</label>
      <input required class="form-control" name="groupid" id="groupid">
    </div>

    {{ force_checkbox("reindex_group_force") }}
  {% endcall %}
{% endblock %}

